package cn.xiaoliu.hrm.config;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
public class CourseNoticeListener {
    public static final String COURSE_ONLINE_NOTICE_QUEUE_SMS = "course_online_notice_queue_sms";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_EMAIL = "course_online_notice_queue_email";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_SYSTEM = "course_online_notice_queue_system";

    //发送短信
    @RabbitListener(queues = COURSE_ONLINE_NOTICE_QUEUE_SMS)
    public void smsHandler(String msg, Message message, Channel channel) throws IOException {
        System.out.println("短信:我们课程{"+msg+"}上线了");
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false );
    }
    //发送邮件
    @RabbitListener(queues = COURSE_ONLINE_NOTICE_QUEUE_EMAIL)
    public void emailHandler(String msg, Message message, Channel channel) throws IOException {
        System.out.println("邮件:我们课程{"+msg+"}上线了");
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false );
    }
    //发送站内信
    @RabbitListener(queues = COURSE_ONLINE_NOTICE_QUEUE_SYSTEM)
    public void systemHandler(String msg, Message message, Channel channel) throws IOException {
        System.out.println("转内信:我们课程{"+msg+"}上线了");
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false );
    }

}
